CHAPTER 5

OBJECTIVES

 INTRODUCTION TO MACHINE LANGUAGE

BUG               

It is the computer terminology for error or mistake in a program or computer system and the term debugging is a methodical process of finding and reducing the number of bugs or defects in a computer program. These terms stemmed from the early days of computing. In particular, it was in 1947 that an event occurred that is of special interest to programmers and students of computing. Grace Murray Hopper, while investigating why MARK Il computer was not working properly, discovered a small, dead moth in the machine and removed it with a tweezers.  

DEBUGGER                

Debugger is a program tool that provides an environment for testing load modules. Load modules are executable files that can have extensions of .COM and -EXE. It also allows us to run machine code programs in such a way that we can observe the changes a program makes to register and memory.  

DEBUG                

In 1980, Tim Paterson began working on a 16-bit OS for the 8086 S-IOO Bus card he had designed for SCP (Seattle Computer Products) the previous year. To help in getting QDOS (later called 86-DOS) to work correctly, Paterson created a debugger in a R0M chip; the code for that ROM version was released into the public Domain. Paterson adapted the code to run as a .COM program under QDOS, and also added the ability to disassemble 8086 machine code. 

MS-DEBUG  DOS 2.0         

With the release of DOS 2.0. DEBUG gained the ability to assemble instruction directly into machine code (the A command). This is one of the most important commands for many of its users.  

DOS 3.0            

Under DOS 3.0, the P (proceed) command Was added, so DEBUG could quicklyexecute subroutines; at the same time, it became possible to attempt stepping through Interrupts with the T (Trace) command. 

DOS 4.0              

When OOS made EMS (Expanded Memory) functions available under DOS 4.0, the four commands xa, xm and were also added to DEBUG. It appears they were rarely, if ever used though, even by programmers. For most of us, the only noticeable change in DEBUG was the addition of the help command (type a while inside DEBUG) under DOS 5.0; when all DOS commands finally got the /? Command-line switch.

  DOS 5.0            

 DEBUG’s code went through a number of changes (and 'bug fixes' too) over the years! Some of these internal changes were related to DOS system calls and screen output, then there was the change in file type from a .COM to an .EXE program under DOS 5.0. But in spite of all those changes and others which followed, DEBUG has never had an official revision since 2.40 (those digits have embedded inside all versions Of DEBUG Since DOS 3.0), 

MASM               

Microsoft did create their Assembler (MASM), 'C' compiler and Debugger (CodeView). Rather than using MASM and CodeView, many opted for the less expensive Borland assembler (TASM) and Turbo Debugger when they appeared or some other commercial product. However, users and students alike can still learn a great deal about Assembly language by using DEBUG. 

-   It is free

-   It is universally available

-   It is simple to use

-   It requires relatively little memory 

DEBUG COMMANDS  

DEBUG set of commands lets you perform a number of useful operations. The commands of interest at this point are the following.  Displays a list of the Debug commands.              

  A             Assembles 8086/8087/8088 mnemonics.              

  C             Compares two portions of memory.               

  D             Displays the contents of a portion of memory.              

  E             Enters data into memory starting at a specified address.               

  F             Fills a range of memory with specified values.            

  G            Runs the executable file that is in memory.               

  H             Performs hexadecimal arithmetic.               

  I               Displays one-byte value from a specified port.               

  L             Loads the contents of a file or disk sectors into memory.              

  M            Copies the contents of a block of memory.            

  N             Specifies a file for an I or w command, or specifies the parameters for the file you are testing.              

  O            Sends one-byte value to an output port.               

  P             Executes a loop, a repeated string instruction, a software interrupt, or a subroutine.

 R             Displays or alters the contents of one or more registers.               

 S             Searches a portion of memory for a specified pattern of one or more byte values.             

 T             Executes one instruction and then displays the contents of alregisters, the Status Of all flags, and the decoded form of the instruction that Debug will execute next. Disassembles bytes and displays                     the corresponding source statements.               

 W            Writes the file being tested to a disk.            

 XA          Allocates expanded memory.               

 XD          Deallocates expanded memory.        

 XM          Maps expanded memory pages.              

 XS          Displays the status of expanded memory. 

       A(Assemble)     

 Assembles 8086/8087/8088 mnemonics directly into memory. This command creates executable machine code from assembly-language statement. All numeric values are in hexadecimal format, and you must type them as I to 4 characters. You specify a prefix mnemonic in front of the operation code (opcode) to Which it refers.

               Svntax:                      a [address]                                                             

                                                  Parameters                                                            

                                                 address                                                              

                                                 Specifies the location where you type assembly-language  mnemonics. You use hexadecimal values for addressand                                                                                                     type specify an address, a start assembling where it last stopped.                                                             

                                                  Notes                                                             

                                               Using mnemonics .The segment-override mnemonics are cs:, es:, and s". The mnemonic for the far return is retf.String- manipulation                                                                        mnemonics must explicitly State the string  size. For example. use movsw to move word strings (16bits), and use movsb to move byte strings (8 bits).

  C (Compare)               

Compares two portions of memory.               

Syntax:                                 c range address                                                             

                                             Parameters                                                             

                                           range                                                            

                                           Specifies the starting and ending addresses, or the  starting address and length, Of the first area of memory  you want to compare. For information                                                                                                   about valid range values, see the debug command.                                                             

                                           address                                                     

                                          Specifies the starting address of the second area Of  m emory you want to compare. For information about valid address, values, see the debug command.                                           Notes                                                            

                                          If the range and address memory areas are identical, Debug displays nothing and returns directly to the Debug prompt.                             

Example:            The following commands have the same effect:                                                            

                          cloo,10f                                                             

                          c100110300                                                            

                        Each command compares the block of memory from 1001 through IOFh with the block of memory frorn 3CX)through Debug responds to either Of the previous                                                                            commands with a display similar to the following  (assuming 197F):                                                            

                        197F AD E4197F:0300                                                            

                        197F:0101 67 99197F;0301                                                             

                        197F:0102 A3 27 197F:0302                                                            

                        197F:0103 35 F3 197F:0303                                                             

                       197F:0104 97 BD 197F:0304                                                           

                       197F:0105 04 35 197F:0305 

                       197F:0107 76 71 197F:0307   

                       197F:0108 E6 11 197F:0308                                                           

                       197F:0109 19 2C 197F0309                                                            

                      191F:010A go OA 197F:030A                                                          

                      197F:010B 36 197F:030B                                                             

                      197F:010C BE 22 197F;030C                                                             

                      197F:010D 93 197F:030D                                                             

                      19/F:010E 49 77 197F:030E                                                             

                      197F;010F 4F 8A 197F;030F                                                             

                      Notice that the addresses 197F:0106 and 197F:0306 are missing from the list. This means that the values in those addresses are identical.

 

D (Dump)              

Displays the contents of a range of memory addresses.              

  Syntax:                                 d[range]                                                            

                                           range                                                            

                                         Specifies the starting and ending addresses, or the address and length, of the memory area whose contents you want to display.For information aboutvalid                                                                                    range values, see the debug command. If you do not specify range, displays the contents of 128 bytes, starting at the end address range specified in the previous d command.                                                

                                        Notes                                                           

                                        When you use the d command, Debug displays memory contents in two portions: a hexadecimal portion (each bytevalue is shown in hexadecimal format)and an ASCII  portion (each byte value is Shown as an ASCII character).  Each nonprinting character is denoted by a period (.) in the ASCII portion of the display, each display line Shows  the contents of 16 bytes, With a hyphen between the eighth and ninth bytes. Each display line begins on a 16 -byteboundary. 

 

Example:                           Suppose type the following command:                                                  

                                         dcs:loo lof                                                         

                                        Debug displays the contents of the range in the following format:                                                       

                                       04BA:01tK1 54 4F AD 00 53 4157 59-45 52 00 00 0000 00                              

                                       TOM.SAWYER….                                                          

                                       If type the d command Without parameters, Debug formats the display as described the previous example  Each line of the display begins with an address that is bytes greater than the address on the previous line (or  bytes if you have a 40-coIumn screen), For each subsequent d command type without parameters, Debug displays the bytes immediately following those last displayed. If you type the following command, Debug displays thiscontents of 20h bytes, starting at CS:100:dcs:100120

                                     If type the following command, Debug displays this contents of all bytes in the range of lines from 100h through 115h in the CS Segment: dcs:100 IIS

 

E (Enter)              

Enters data into memory at the address you specify. You can type data in either hexadecimal or ASCII format. Any data previous stored at the specified address is lost.

Syntax:                                   e address [list]                                                            

                                             Parameters                                                             

                                             address                                                            

                                           Specifies the first memory where you want to data,                                                            

                                             list                                                            

                                      Specifies thedata you want to enter into successive bytes of memory.

Notes

Using the address parameter              

  If you specify a value for address without specifying a value the optional list parameter, Debug displays the address and its contents. repeats the address On the next line, and for your input. At this point, you Can perform one of the following actions:

Ø  Replace the byte value. TO do this, you type a new value after the current value. If the value you type is not a valid hexadecimal value or if it contains more than two digits, Debug does not echo the invalid or extra character.

Ø  Advance to the next byte. To do this, you press the SPACEBAR. To change the value in that byte, type a new value after the current value. If you move beyond an 8-byte boundary when you press the SPACEBAR, Debug starts a new display line and displays the' new address at the beginning of the line.

Ø  Return to the preceding byte. To do this, you press the HYPHEN keys. You can press the HYPHEN key repeatedly to move back more than 1 byte. When you press HYPHEN, Debug starts a new line and displays the current address and byte value. Stop the e command. To do this, you press the ENTER key. You can press ENTER at any byte position.

 

Using the list parameter              

  If you specify values for the list parameter, the e command sequentially replaces the existing byte values with the values from the list. If an error occurs, no byte values are changed. List values can be either hexadecimal byte values or strings. You separate values by using a space, a comma, or a tab character. You must enclose Strings within single or double quotation marks.

Example:                                            Suppose you type the following command:                                              

                                                          ecs:100                                             

                                                        Debug displays the contents of the first byte in the following                    

                                                       format:                                             

                                                       04BA:0100 EB. _                                              

                                                      To change this value to 41, type 41 at the cursor, as follows:                                          

                                                      04BA:0100 EB.41_                                            

                                                      You can type consecutive byte values with one e command.Instead of pressing ENTER after typing the new value, press

the SPACEBAR. Debug displays the next value. In this                                              

example, if you press the SPACEBAR three times, Debug                                              

displays the following values:                                             

  04BA:0100 FR.41 10. 00. BC.                                              

To change the hexadecimal value BC to 42, type 42 at the        

                                       cursor, as follows:                                        

       04BA:0100 EB.41 10.00. BC.42                                             

Now suppose that you decide the value 10 should be 6F. To                  

                             correct this value, press the HYPHEN key twice to return to         

                                      address 0101 (value 10). Debug displays the following:    

                                           04BA:0100 EB.41 10.00. BC.42.                                      

                                            04BA:0102 00.-                                             

                                            04BA:0101 10. _                       

                                          Type 6f at the cursor to change the value, as follows:           

                                            04BA. -0101 10.6f_                                              

                                       Press ENTER to stop the e command and return to the Debug prompt. The following is an example of a string entry:    

                                       eds:100 "This is the text example" This string will fill 24 bytes, starting at DS: 100.

F (Fill)               

Fills addresses in the specified memory area with values you specify. You can specify data in either hexadecimal or ASCII format. Any data previously stored at the specified address is lost.              

Syntax:                                 f range list                                                            

                                           Specifies the starting and ending addresses, or the starting address and length, of the memory area you want to fill. For information about valid range                                                 values, see the debug command.                                                             

                                            list                                                            

                                        Specifies the data you want to enter. List can consist Of  hexadecimal numbers or a string enclosed in quotation marks.

Notes

Using the range parameter         

 If range contains more bytes than the number of values lists, Debug assigns the values in list repeatedly until all by' in range are filled. If any of the memory in range is bad or doesn't exist, Debug displays an error message and stops the f command.

Using the list parameter               

If list contains more values than the number of ranges, Debug ignores the extra values in list.  

 

Example:                              Suppose you type the following command:                                              

                                            f04ba:1tnn) 42 45 52 54 41

                                            In response Debug fills memory locations 04BA:100 through 04BA:1FF with the values specified. Debug repeats the                                                                                                  values until all the 100h bytes are filled.

G (Go)               Runs the program currently in memory.               

Syntax:                  g [=address] [breakpoints]

                              Parameters                                              

                             =address                                             

                         Specifies the address in the program currently in memory which you want execution to begin. If you do not address, MS-DOS  begins program execution at the current address in the CS:                                        Iregisters.

                         breakpoints                                             

                        Specifies 1 to 10 temporary breakpoints that you can set as, Part Of the g command.

                         Notes                                             

                       Using the address parameter                                              

                      You must precede the address parameter with an equal sign (=) to distinguish the starting address (address) from theBreakpoint addresses (breakpoints).

                     Specifying breakpoints                                             

                     The program Stops at the first breakpoint it encounters, regardless  of where you typed that breakpoint in the breakpoints list. Debug replaces the original instruction at each breakpoint with an interrupt Code.When the program reaches a breakpoint, Debug restores all breakpoint addresses to their original instructions andisplaysthe contents of all registers, the status of all flags, and the decoded form of the last instruction executed. Debug displays the same information as it would display if you used the Debug r (register)  command and specified the breakpoint address. If you do not stop the program at one of the breakpoints, Debug does not replace the interrupt codes With the Original instructions.                                              

                    Limitations on setting breakpoints                                              

                   You can set breakpoints only at addresses containing the first byte  Of an 8086 operation code (opcode). If you set more than 10breakpoints, Debug displays the                                 followingmessage: bp Error

 

                      Requirements for the user stack pointer The user stack pointer must be valid and must have 6 by available for the g command. This command uses an iret instruction to jump to the program being tested. Debug sets the user stack pointer and pushes the user flags, the code segment  register, and the instruction pointer onto the user stack. (If the user stack is not valid or is too small, the operating system might fail.)   Debug places an interrupt code (OCCh) at the specified breakpoint  address(es).

                      Restarting a program                                              

                    Do not attempt to restart a program after MS-DOS displays the following message: Program terminated normally  To run the program properly, you must reload it by using the Debug n (name) and I (load) commands.

Example:                             Suppose you type the following command:                                              

                                           gcs:7550                                              

                                         MS-DOS runs the program currently in memory up to the breakpoint address 7550 in the CS segment, Debug then displays the contents of the registers                                                                                                 and the status of the  flags and stops the g command.  The following command sets two breakpoints:  go: 7550,

H (Hex)               

Performs hexadecimal arithmetic on two parameters you specify.               

Syntax:                  h value1 value2                                              

                               Parameters                                              

                               value1                                             

                              Represents any hexadecimal number in the range 0 through                                              

                             FFFFh                                             

                              value2                                          

                            Represents a second hexadecimal number in the range 0 through                                         

                            FFFFh.

                             Note                                             

                           Debug first adds the two parameters you specify and then subtracts the second parameter from the first The results these calculations                             

                           are displayed on one line — first the sum, then the difference.

 

Example:                               Suppose you type the following command:                                              

                                              h19f 10a                                              

                                            Debug performs the calculations and displays the following result:

 

 I (Port)               Reads and displays one byte value from the port you specify. 

 

 Syntax:                  i port                                              

                               parameter                                              

                               port                                             

                              Specifies the input port by address. The address can be a 16- bit  value. 

 

Example:               Suppose you type the following command:                                             

                             i2f8                                              

                           Suppose also that the byte value at the port is 42h. Debug reads the byte and then displays the value, as follows: 42

 (Read)              

      Loads a file or contents of specific disk sectors into memory. To load the contents of the number of bytes specified in the BX:CX registers from a disk file, use the following syntax:

 Syntax:                  I [address]                                             

                              To bypass the MS-DOS file system and directly load specific sectors, use the following syntax: I address drive start number                                            

                             Parameters                                             

                              address                                             

                            Specifies the memory location where you want to load the file or the  sector contents. If you do not specify address, Debug uses the current address in the                                         CSregister. 

                            drive                                             

                         Specifies the drive that contains the disk from which specific sectors are to be read. This value is numeric: 0 =A,1= B,2=C and so on. You use the drive, start, and number parameters only if  you want to load the contents Of specific sectors rather than load the file specified on the debug command line Or in the most recent Debug n (name) command.

                          Start                                             

                    Secifies the hexadecimal number Of the first sector whose  contents you want to load.                                             

                    number                                             

                     Specifies the hexadecimal number of consecutive sectors whose contents you want to load.

                     Notes                                            

                 Using the I command without parameters       

                  When you use the I command without parameters, the file you  specified on the debug command line is loaded into memory, beginning at address CS:100. Debug also sets the BX and CX registers to the number Of bytes loaded. If you did not specify a file  on the debug command line, the file loaded is the One you mostrecently specified by using the n command.

                   Using the I command with the address parameter         

                   if you use the I command with the address parameter, Debug begins loading the file or the contents Of the specified sectors at the memory location address 

                     Using the I command with all parameters                                              

                    If you use the I command with all parameters, Debug loads the contents Of specific disk sectors instead of loading a file.

                   Loading the contents of specific sectors                                          

                   Each sector in the range you specify is read from drive. Debug begins loading With Start and continues until the contents Of the number of sectors specified in number have been loaded.

                  Loading an .EXE file                                            

                  Debug ignores the address parameter for -EXE files. If you specify an .EXE file, Debug relocates the file to the loading addressspecified in the header Of the .EXE file.The header itself is stripped Off the .EXE file before the file is loaded into memory, so the size Of an .EXE file on disk differs from its size memory. If you want to examine a complete .EXE file, rename the file With a different extension.

M (Move)                Copies the contents of a block of memory to another block of memory.

Syntax:                                  m range address

                                              Parameters                                                                                            

                                              range                                             

                                          Specifies the starting and ending addresses, or the starting  address and the length, of the memory area whose contents you want to copy.                                                                       address                                              

                                         Specifies the starting address of the location to which you want to copy the contents of range  

                                             Notes                                              

                                         Effects of the copy operation on existing data   

                                       If the addresses in the block being copied do not have data written  to them, the original data remains intact, However, if the destination block already contains data (as it might in an overlapping copy operation), that data is overwritten. (Overlapping copy operations are those in which part of                                         the destination block overlaps part of the source block.)

N (Name)              

  Specifies the name of an executable file for a Debug I (load) or w (write) command, or specifies parameters for the executable file being debugged.

Syntax:                                 n [drive:][path]filename                                              

                                            To specify parameters for the executable file you are testing, use the following syntax: n file-parameters                                              

                                            To clear the current specifications use the following syntax: n

                                             Parameters                                              

                                          [drive:][path] filename                                             

                                         Specifies the location and name of the executable file you

                                           file -parameters                                              

                                        Specifies parameters and switches for the executable file you are testing.

                                          Notes                                              

                                         The two uses of the n command                                          

                                       You can use the n command in two ways. First, you can use it to specify a file to be used by a later I or w command. If you start Debug without naming a                                             file to be debugged, you must use the  command n filename before you can use the I command to load the  file. The filename is correctly formatted for a file control block at CS:5C. Second, you can use the n command to specify command- line parameters and switches for the file being debugged.

O (Output)             

   Sends the value of a byte to an output port.

Syntax:                                 o port byte-value                                             

                                              parameters                                              

                                              port                                            

                                            Specifies the output port by address. The port address can be a 16-bit value.                                        

                                           byte-value                                        

                                         Specifies the byte value you want to direct to port.  

Example                             To send the byte value 4Fh to the output port at address 2F8h, type the following command:                                              

                                         o2f8 4f

P (Proceed)               

Executes a bop, a repeated string instruction, a software interrupt, or a subroutine; or traces through any other instruction.

Syntax:                                 p [=address][number]                                                                                           

                                             Parameters                                              

                                            = address                                              

                                           Specifies the location Of the first instruction to execute. If do not specify an address, the default address is the current address specified in the CS:IP                                                    registers.  

                                           number                                              

                                         Specifies the number of instructions to execute before returning control to Debug. The default value is 1.

Q (Quit)               

   Stops the Debug Session Without saving the fi e currently being tested.               

After you type q, control returns to MS-DOS.

 

Syntax                   q

Example                      To stop the debugging session, type the following command:

                                  q

                                   MS-DOS displays the MS-DOS prompt.

Debug: R (Register)             

   Displays or alters the contents of one or more central-processing-unit (CPU) registers.

Syntax                   r [register-name]

                          To display the contents of all registers and flags in the register storage area, use the following syntax: r

                         Parameter                                             

                         register-name                                             

                        Specifies the name of the register whose contents you want to Display.  

 

S (Search)          

     Searches a range of addresses for a pattern of one or more byte values.        

        Syntax                   s range list  

                                      Parameters                                              

                                    Specifies the beginning and ending addresses of the range you want to search. For information about valid values for the range                                                                                  parameter, see the debug command.

                                      list                                             

                                  Specifies the pattern of one or more byte values or a string you  want to search for, Separate each byte value from the next With a space or a comma. Enclose string values quotation marks.

                                   Note                                               

                              If the list parameter contains more than one byte Debug displays only the first address where the byte value occurs. If list contains only one byte value, Debug    displays addresses where the value  occurs in the specified range.

 

T (Trace)            

    Executes one instruction and displays the contents of all registers, the status of all flags, and the decoded form of the instruction executed.

Syntax                   t [=address][number]                                             

                             parameters                                             

                            Specifies the address at which Debug to start tracing instructions. If you omit the address parameter, tracing begins at the address specified by your program's CS:1P registers. For information about valid values for the address parameter, see the debug command.

                            number                                             

                           Specifies the number of instructions to be traced. This value must be a hexadecimal number. The default value is 1.

                            Notes                            

                           Tracing instructions in read-only memory                

                               The t command uses the hardware trace mode of the 8086 or 8088 microprocessor. Therefore, you can also trace instructions stored  read-only memory (ROM).

                          Using the address parameter                                          

                         You must precede the address parameter with an equal sign (=) to  distinguish it from the number parameter

U (Unassemble)              

Disassembles bytes and displays their corresponding source statements including addresses and byte values. The disassembled code looks like a listing for an assembled file.

 

Syntax                   u [range]                                             

                             To disassemble 20h bytes (the default number), beginning at the first address after the displayed previous u command, the following; Syntax; u

                              Parameter         

                               range   

                             Specifies the starting and addresses, or the starting address and length, Of the code you want to disassemble. For information about valid values for the range parameter, see the debug command.

 

W (Write)              

   Writes a file or specific Sectors to disk.    You must have specified the name of the disk when you started Debug on the most recent Debug n (name) command. Both  of these methods proper format a filename for a file control block at address CS:5C.to write the contents of the of bytes in the BX:CX register a disk fil, use the following syntax:

Syntax:                  w [address]                                             

                             To bypass the MS-DOS file system and directly write specific sectors, use the following Syntax; w address drive number  

                             Caution: Writing specific sectors is extremely risky because bypasses the MS-DOS file handler. The disk's file structured easily be damaged if the wrong values are typed

                             Parameter                                             

                             address                                             

                          Specifies the beginning memory address of the file, or of the file,  you want to write to a disk file. If you specify address. Debug Starts from CS:100. For information about valid values for the                       address parameter, see the command.

                          drive                                             

                         Specifies the drive that Contains the destination disk value is numeric: O 1 B, 2 C, and so on.

 

 XA (Allocated Expanded Memory)           

     Allocates a specified of pages of expanded memory. to use expanded memory, you must have installed an expanded-memory device driver that conforms to version 4.0 Of the Lotus/intel/Microsoft  Expanded Memory  Specification (LIM EMS).

Syntax:                  xa [count]

                            Parameters                                            

                           count                                              

                           Specifies the number Of Is-kilobyte pages of expanded memory to  allocate.

Example              To deallocate handle 0003, type the following command: xd 0003                                    

                           If the command is successful, Debug displays the followingmessage:                                             

                           Handle 0003 deallocated

 

XD (Deallocated Expanded Memory)              

  Deallocates a handle to expanded memory. To use expanded memory, you must have installed an expanded-memory device driver that conforms to version 4.0 Of the Lotus/Intel/Microsoft Expended Memory Specification (LIM EMS).

                Parameters                                          

                Specifies the handle vou want to deallocate.                

Example             To deallocate handle 0003, type the following command:                                                                                                          

                          xd 0003

                        If the command successful, Debug displays the following message:Handle 0003 deallocated

XM (Map Expanded Memory pages)         

       Maps a logical page of expanded memory, belonging to the specified handle to a  physical page of expanded memory. TO use expanded memory, have installed an device driver that conforms to version 4.0 Of the Lotus/intel/Microsoft Expanded Memory Specification (LIM EMS).

Syntax             xm [lpagel][ppage][handle/]

                       lpage                                             

                    Specifies the number of the logical page of expanded memory  that you want to map to physical page ppage.                                              

                   ppage                                             

                 Specifies the number of the physical page to which lpage is to be mapped.  

                  handle                                             

                Specifies the handle.

Debug: XS (Display Expanded-Memory Status)               

  Displays information about the status of expanded memory. To use expanded memory, you must have installed an expanded-memory device driver that conforms to version 4.0 of the Lotus/intel/Microsoft Expanded Memory Specification (LIM EMS).

Syntax                   xs                                       

                            Note                                            

                         The information that Debug displays has the following format; 

                         Handle xx has xx pages allocated                                              

                         Physical page xx= Frame segment xx                                             

                         xx of a total EMS pages have been allocated                                         

                         xx of a total EMS handles have been allocated

 

RULES OF DEBUG COMMANDS

Here are some basic rules in using DEBUG.

Ø  It not case-sensitive.

Ø  It assumes that all numbers given are in hexadecimal format.

Ø  You can enter a space only when it is needed to separate parameters of a
particular command.

Ø  You should specify segments and offsets with a colon, in the form <segment>:<offset>.

 

A SAMPLE SESSION WITH DEBUG Below are the illustrations that will demonstrate how to use DEBUG.

 Starting DEBUG From the DOS prompt, key in the word DEBUG and press ENTER key. A hyphen (-) appears on screen; that is the DEBUG prompt. DEBUG us now ready to accept

 


0%;font-family:"Arial",sans-serif;'>Quitting and closing the DEBUG environment
To close DEBUG and go back to DOS environment. Tyoe Q and press <ENTER> key.

                                               image
Adding and subtracting a-digit hexadecimal Values 
To get the sum and difference of two hexadecimal numbers: type H followed by a space, 
a 4-digit hexadecimal value followed by a space again, another 4-digit hexadecimal value 
and then press <ENTER> key. The leftmost pat is the sum and the rightmost part is the 
difference.
 
Viewing the contents of the registers 
TO show the values of the registers: type R and press <ENTER>key.
                                               image
Changing the contents Of a specific register TO modify the value if a particular register, let's say BX:type R followed by a space, type
BX and press <ENTER>. Debug Will display the current value of BX (i.e. 0000) and Will
wait for you to enter the new value. Just type in the new value in hexadecimal form
after the colon and press CENTER;' key. TO confirm if the new value for BX is stored, 
type R to display the values Of the registers. image
Entering String 
Lets store the string into memory. Well start at offset 021nh so that the string wont become tangled With the code at 0100h. Here are the Steps: Step I: Convert every character into its hexadecimal equivalent code using the ASCII reference table. image Step 2: Add the last number 24h which is the ASCII for $ symbol. It tells DOS that this is the end Of the string.
                                               image

Step 3:Enter these hex codes using the command E 0200. Type E 0200 after the DEBUG prompt and press ENTER key. Key in the first hex code (i.e. 48) and press SPACE bar. Key in the second hex code (i.e. 65) and press SPACE bar. Do it over and over again until you have entered 24 for the dollar sign. Press ENTER key to end the process.

    
 
The display consist of the three parts.
  • The address in segment:offset format. 
  • The hexadecimal representation are those that shows (2) hex digit for each byte, followed by a space for readability. Also, a hyphen separates the second 8 bytes from the first 8. 
  • The ASCII representation of bytes that contains displayable characters, which can help you, interpret the hex representation. 
Take note that the remaining characters displayed after the dollar (S) sign are the miscellaneous assortment of characters. Whenever you see a period (.) in the ASCII window, it represents either a period or a special character such as the Greek letter alpha. DEBUG's D command displays only 96 out Of 256 characters in the ASCII table so a period is used for the remaining 160 characters. 
Creating a program in DEBUG 

TO construct a program in DEBUG: type A and press <ENTER>key. This command tells DEBUG to begin accepting symbolic assembly instructions and initializes the starting address;

Running the entire program 
To execute the entire symbolic assembly program: type G and press <ENTER> key. DEBUG will display the output and the message "Program terminated normally". Let's have a new set of
program this time, key in the following instructions each followed by pressing <ENTER> key: 
MOV AX, OBEA MOV ex, 0103 ADD AX, BX INT 2>0 image
Saving your program TO save your work in DEBUG follow the procedures below: (Well assume that were going to save the program illustrated above in the same path drive C:.) Step 1:Determine the number of bytes by subtracting the last offset address(before the DEBUG prompt) from 0100. Type H 0108 0100 press CENTER key. Get the rightmost value of the difference (0008) Step 2:Store that value (0008) to CX register. Type R CX press ENTERkey, after the colon type in and pressENTERkey again. Step 3: Give the filename Type N SAMPLE.COM and press ENTER key. Step 4:Save the program onto disk storage by using W commandType W and press ENTER key, the message Writing 0008 bytes Will be displayed On screen.
Step 5:Lastly, check if the DEBUG program was stored by quitting DEBUG andusing dir *.com DOS command to view the contents to the disk storage.
                                               image
image

To execute your DEBUG program in DOS environment, just type only the base name (no need to add the extension name .COM) and press ENTER key.
                                               image
Loading you DEBUG program To retrieve your DEBUG program for modification, type DEBUG followed by a space and the file name. This time add the extension name COM (i.e. DEBUG SAMPLE.COM) and press ENTER key. Debug prompt will be displayed on screen which means it is ready to accept any modification. From the DEBUG prompt, type U 0100 and press ENTER key. Your program Will be listed down on screen.
image
Modifying Instruction in DEBUG To change a particular instruction in DEBUG, type A followed by space, followed by the Offset address and press ENTER key. DEBUG is now ready to accept a new instruction for this offset address. For example, instead Of MOV DL, 01, your instruction is MOV DL, 03. TO do this, type A 0102 and press ENTER key. Type MOV DL, 03 and press ENTER and ENTER key again. If

ADDITION AND SUBTRACTION, MACHINE LANGUAGE STYLE 

The machine code to add the values of Ax and BX is Olh and D8h, while to subtract their values is 29h and D8h. These numbers have no meaning to us, but the computer will interpret as add and subtract instructions. 

As an example, let's add and subtract 083Ah and 050Ch. TO do this, follow the process below: 

Step l: Store 083Ah to AX, while 050Ch to BX register.
 
 
  




Step 2: Input the numbers 01h and D8h using E command.




Step 3: Display the register and trace if the instruction will work.

For subtraction, apply the same procedure but use different machine code. Try it in your computer.
MULTIPLICATION AND DIVISION, MACHINE LANGUAGE STYLE
 
As an example, let's multiply and divide 0808h and 0300h. To do this, follow the process below: 

    
Step 1: Store 0808h to AX, while 0300h to BX register.

Step 2:  Input the numbers F7h and E3h using E command

Step 3: Display the register and trace if the instruction will work.

In multiplication, when the product greater than 16-bit result, the higher 16-bits are stored in DX register. For division, the quotient is stored AX while the remainder is stored in DX. Now try dividing the sample numbers in your computer.

THE INSTRUCTION SET 
The 8086 / 8088 instruction set includes equivalents to the instructions found in the 8086 or almost any 8-bit microprocessor plus some new operations. The instruction categories include: 

I.          Data Transfer - that move bytes or words of data between memory and register as well as between accumulator and the I/O parts. 
II.         Arithmetic - Capable of adding, subtracting, multiplying and dividing data as either bytes or words. 
III.       Program Transfer - Include, Jump, and Call and return instructions familiar in the 8085 as well as some addition instructions that form loops. 
IV.       Bit manipulation — to manipulate digits in terms of bit. 
V.        String Instruction — used to manipulate string of data in the memory. 
VI.       Processor Control — Output of the microprocessor. Instructions enable or disable interrupts modify the flag bits, and synchronized external element.
l. DATA TRANSFER 
Data-Addressing Modes 
Because the MOV instruction is one of the simplest and most flexible of the 8086/8088 instructions. 
The MOV instruction and defines the direction of the data flow. 
 Notice that the source is far to the right and the destination is next to the OPCODE with the source and destination separated by a comma.  
ILLUSTRATION:




The instruction MOV AX, BX transfers the contents of the source register (BX) into the destination register (AX). In other words, this instruction copies the contents of the BX register into the AX register is very important to note that the source never changes and the destination almost always changes.

The data-addressing modes used with this instruction include: 
Register Addressing - used to transfer the immediate byte or word of data to the destination register.
 
 

Immediate Addressing — used to transfer the immediate bytes or word of data to the destination register.
 

Direct Addressing — transfer a byte or word between the memory and a register. The memory address of the data is stored with the instruction.
 







Register Indirect Addressing - Transfer a byte or word between a register and the memory location addressed by a register.
 
 
  
 
Based-plus-Index Addressing — used to transfer a byte or word or between register and the memory location indicated by the sum of a base register and an index register.

II. ARITHMETIC OPERATIONS 

a.    ADDITION OPERATIONS

 
b.    SUBTRACTION OPERATIONS

 
a.MULTIPLICATION OPERATIONS
Multiplication, whether 8 or 16 bit, can be either signed (IMIJL) or unsigned (MUL). Multiplication always results in a double-width product. In 8- bit multiplication, whether signed or unsigned, the multiplicand is always in the AL register. Because the programmer can choose only the multiplier, the symbolic coded version of this instruction specifies only one operand. For example MUL BL will multiply AL by BL and leave the 16-bit product in AX.

ILLUSTRATION:
        
b.DIVISION OPERATIONS 
 Like division in the 8086/8088 can also occur on 8-bit or 16-bit numbers. Numbers are always divided into a double-width. For example, an 8- bit division always divided into a 16-bit dividend. As in multiplication, there is no immediate division instruction. A dividend for an 8-bit division is located in the AX register and the divisor is the operand selected for the instruction. The results of an 8-bit division are two 8-bit numbers: the quotient (AL) and the remainder (AH).

ILLUSTRATION: 

              
 
Ill. PRORAM TRANSFER 

               LOOP (Loop Until Complete) 
               It controls the execution Of a program segment in a specified number Of times. 
               The CX register should contain a count value before starting the loop and 
               automatically decrements by One If CX register is not equal to zero it 
               transfers to its operand address which points to the Start Of the loop; Otherwise 
               it drops through to the next instruction. 

               Format:                  LOOP <offset address>

               Example:               LOOP 0108

  
  
PROGRAMMING USING DEBUG 
Displaying character (uppercase 'A') on screen.

Displaying character (lowercase 'b') twice on screen.
 
 
 
Using control characters (OA — Line feed and OD — Carriage Return) in a screen display.

 
 Displaying different character to '9') using LOOPS with separator (underscore) horizontally.







Displaying string ('computer') on screen. 
                               
Step 1: Code the instruction at —A 0100.



Step 2: Input the hex code of every character of the string at—E 0200.
 
Step 3: Press ENTER key to go back to the hyphen prompt, then key in —D 0200 and press ENTER key to display the string.